package cn.chinasyq.photoquan.photo.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;

import cn.chinasyq.photoquan.R;
import cn.chinasyq.photoquan.photo.bean.GameEntity;

/**
 * Created by 一搏 on 2015/12/17.
 */
public class GameListAdapter extends BaseAdapter {
    private ArrayList<GameEntity> albums;

    public GameListAdapter() {
        albums = new ArrayList<>();
    }

    @Override
    public int getCount() {
        return albums.size();
    }

    @Override
    public Object getItem(int position) {
        return albums.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        GameEntity item = (GameEntity) getItem(position);
        if (convertView == null || convertView.getTag() == null || !(convertView.getTag() instanceof ViewHolder)) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_games, null);
            viewHolder.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tv_title.setText(item.getTitle());
        return convertView;
    }

    public void setAlbums(ArrayList<GameEntity> albums) {
        this.albums = albums;
        notifyDataSetChanged();
    }

    public void addAlbums(ArrayList<GameEntity> albums) {
        this.albums.addAll(albums);
        notifyDataSetChanged();
    }

    class ViewHolder {
        TextView tv_title;
    }
}
